fix: add debug logging for sandbox 400 errors#106
Conversation
Logs sandboxId, cwd, command details when runCommand fails to help diagnose transient Vercel Sandbox API errors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe change adds error handling with structured logging around the sandbox command execution in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/sandboxes/runClaudeCodeAgent.ts (1)
46-48: Removeas anyand use proper SDK types forcommandOpts.The properties in
commandOpts(cmd, args, cwd, detached, env) all match the valid@vercel/sandbox1.8.0runCommand()options. Instead of declaringcommandOptsasRecord<string, unknown>and casting withas any, import the proper type from@vercel/sandbox(e.g.,RunCommandOptionsor the object parameter type) to let the compiler validate option correctness at build time. This catches contract drift earlier without sacrificing runtime behavior.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/sandboxes/runClaudeCodeAgent.ts` around lines 46 - 48, Change the loose typing on commandOpts to the real SDK type and remove the cast: import the appropriate RunCommandOptions (or the exact parameter type name) from `@vercel/sandbox` and declare commandOpts as that type instead of Record<string, unknown>; then call sandbox.runCommand(commandOpts) without using "as any". Update any related local properties (cmd, args, cwd, detached, env) to satisfy the imported type so the compiler validates the options for sandbox.runCommand.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/sandboxes/runClaudeCodeAgent.ts`:
- Around line 50-58: The catch block that reports a failed sandbox.runCommand
call should not allow logStep failures to replace the original error; wrap the
logStep(...) call in its own try/catch so logging is best-effort and any
exception thrown by logStep is swallowed or recorded separately, then rethrow
the original error variable (error) from the catch in runClaudeCodeAgent.ts;
ensure you reference the existing symbols logStep, sandbox.runCommand, and the
caught error variable so the original error is always propagated.
---
Nitpick comments:
In `@src/sandboxes/runClaudeCodeAgent.ts`:
- Around line 46-48: Change the loose typing on commandOpts to the real SDK type
and remove the cast: import the appropriate RunCommandOptions (or the exact
parameter type name) from `@vercel/sandbox` and declare commandOpts as that type
instead of Record<string, unknown>; then call sandbox.runCommand(commandOpts)
without using "as any". Update any related local properties (cmd, args, cwd,
detached, env) to satisfy the imported type so the compiler validates the
options for sandbox.runCommand.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 090fc701-681a-4acd-b3b3-34b4502d9a5b
📒 Files selected for processing (1)
src/sandboxes/runClaudeCodeAgent.ts
| logStep(`${label} - sandbox.runCommand failed`, false, { | ||
| error: error instanceof Error ? error.message : String(error), | ||
| sandboxId: sandbox.sandboxId, | ||
| cwd, | ||
| cmd: "claude", | ||
| argsLength: args.length, | ||
| messageLength: message.length, | ||
| }); | ||
| throw error; |
There was a problem hiding this comment.
Preserve the original runCommand error if step logging fails.
Line 50 logging is inside the catch path; if logStep() throws, it can mask the root sandbox.runCommand failure. Make this diagnostics logging best-effort, then rethrow the original error.
Suggested fix
} catch (error) {
- logStep(`${label} - sandbox.runCommand failed`, false, {
- error: error instanceof Error ? error.message : String(error),
- sandboxId: sandbox.sandboxId,
- cwd,
- cmd: "claude",
- argsLength: args.length,
- messageLength: message.length,
- });
+ try {
+ logStep(`${label} - sandbox.runCommand failed`, false, {
+ error: error instanceof Error ? error.message : String(error),
+ sandboxId: sandbox.sandboxId,
+ cwd,
+ cmd: "claude",
+ argsLength: args.length,
+ messageLength: message.length,
+ });
+ } catch {
+ // Best-effort logging only; do not mask the original failure.
+ }
throw error;
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/sandboxes/runClaudeCodeAgent.ts` around lines 50 - 58, The catch block
that reports a failed sandbox.runCommand call should not allow logStep failures
to replace the original error; wrap the logStep(...) call in its own try/catch
so logging is best-effort and any exception thrown by logStep is swallowed or
recorded separately, then rethrow the original error variable (error) from the
catch in runClaudeCodeAgent.ts; ensure you reference the existing symbols
logStep, sandbox.runCommand, and the caught error variable so the original error
is always propagated.
Summary
Adds error logging with sandbox context (sandboxId, cwd, command details) when
sandbox.runCommand()returns a 400 error, to help diagnose the recurring clone failures.Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit